﻿<UserControl x:Class="YoderZone.Extensions.Options.Controls.Elements.TinySlider"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:elements="clr-namespace:YoderZone.Extensions.Options.Controls.Elements"
             Height="14"
             d:DesignWidth="300"
             mc:Ignorable="d">
    <UserControl.Resources>
        <SolidColorBrush x:Key="SliderThumb.Static.Foreground"
                         Color="#FFB0B0B0" />
        <SolidColorBrush x:Key="SliderThumb.MouseOver.Background"
                         Color="#FFBEE6FD" />
        <SolidColorBrush x:Key="SliderThumb.MouseOver.Border"
                         Color="#FF3C7FB1" />
        <SolidColorBrush x:Key="SliderThumb.Pressed.Background"
                         Color="#FFC4E5F6" />
        <SolidColorBrush x:Key="SliderThumb.Pressed.Border"
                         Color="#FF2C628B" />
        <SolidColorBrush x:Key="SliderThumb.Disabled.Background"
                         Color="#FFF4F4F4" />
        <SolidColorBrush x:Key="SliderThumb.Disabled.Border"
                         Color="#FFADB2B5" />
        <SolidColorBrush x:Key="SliderThumb.Static.Background"
                         Color="#FFDDDDDD" />
        <SolidColorBrush x:Key="SliderThumb.Static.Border"
                         Color="#FF707070" />
        <SolidColorBrush x:Key="SliderThumb.Track.Border"
                         Color="#FFB0B0B0" />
        <SolidColorBrush x:Key="SliderThumb.Track.Background"
                         Color="#FFE7EAEA" />
        <Style x:Key="RepeatButtonTransparent"
               TargetType="{x:Type RepeatButton}">
            <Setter Property="OverridesDefaultStyle"
                    Value="true" />
            <Setter Property="Background"
                    Value="Transparent" />
            <Setter Property="Focusable"
                    Value="false" />
            <Setter Property="IsTabStop"
                    Value="false" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type RepeatButton}">
                        <Rectangle Width="{TemplateBinding Width}"
                                   Height="{TemplateBinding Height}"
                                   Fill="{TemplateBinding Background}" />
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
        <ControlTemplate x:Key="SliderThumbHorizontalDefault"
                         TargetType="{x:Type Thumb}">
            <Grid HorizontalAlignment="Center"
                  VerticalAlignment="Center"
                  UseLayoutRounding="True">
                <Path x:Name="grip"
                      VerticalAlignment="Center"
                      Data="M 0,0 L6,0 6,9 0,9 0,0 z"
                      Fill="{StaticResource SliderThumb.Static.Background}"
                      SnapsToDevicePixels="True"
                      Stretch="Fill"
                      Stroke="{StaticResource SliderThumb.Static.Border}"
                      StrokeThickness="1"
                      UseLayoutRounding="True" />
            </Grid>
            <ControlTemplate.Triggers>
                <Trigger Property="IsMouseOver"
                         Value="true">
                    <Setter TargetName="grip"
                            Property="Fill"
                            Value="{StaticResource SliderThumb.MouseOver.Background}" />
                    <Setter TargetName="grip"
                            Property="Stroke"
                            Value="{StaticResource SliderThumb.MouseOver.Border}" />
                </Trigger>
                <Trigger Property="IsDragging"
                         Value="true">
                    <Setter TargetName="grip"
                            Property="Fill"
                            Value="{StaticResource SliderThumb.Pressed.Background}" />
                    <Setter TargetName="grip"
                            Property="Stroke"
                            Value="{StaticResource SliderThumb.Pressed.Border}" />
                </Trigger>
                <Trigger Property="IsEnabled"
                         Value="false">
                    <Setter TargetName="grip"
                            Property="Fill"
                            Value="{StaticResource SliderThumb.Disabled.Background}" />
                    <Setter TargetName="grip"
                            Property="Stroke"
                            Value="{StaticResource SliderThumb.Disabled.Border}" />
                </Trigger>
            </ControlTemplate.Triggers>
        </ControlTemplate>
        <ControlTemplate x:Key="SliderHorizontal"
                         TargetType="{x:Type Slider}">
            <Border x:Name="border"
                    Background="{TemplateBinding Background}"
                    BorderBrush="{TemplateBinding BorderBrush}"
                    BorderThickness="{TemplateBinding BorderThickness}"
                    SnapsToDevicePixels="True">
                <Grid>
                    <Border x:Name="TrackBackground"
                            Height="4.0"
                            Margin="5,0"
                            VerticalAlignment="center"
                            Background="{StaticResource SliderThumb.Track.Background}"
                            BorderBrush="{StaticResource SliderThumb.Track.Border}"
                            BorderThickness="1">
                        <Canvas Margin="-6,-1">
                            <Rectangle x:Name="PART_SelectionRange"
                                       Height="4.0"
                                       Fill="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"
                                       Visibility="Hidden" />
                        </Canvas>
                    </Border>
                    <Track x:Name="PART_Track">
                        <Track.DecreaseRepeatButton>
                            <RepeatButton Command="{x:Static Slider.DecreaseLarge}"
                                          Style="{StaticResource RepeatButtonTransparent}" />
                        </Track.DecreaseRepeatButton>
                        <Track.IncreaseRepeatButton>
                            <RepeatButton Command="{x:Static Slider.IncreaseLarge}"
                                          Style="{StaticResource RepeatButtonTransparent}" />
                        </Track.IncreaseRepeatButton>
                        <Track.Thumb>
                            <Thumb x:Name="Thumb"
                                   Width="8"
                                   Height="12"
                                   VerticalAlignment="Center"
                                   Focusable="False"
                                   OverridesDefaultStyle="True"
                                   Template="{StaticResource SliderThumbHorizontalDefault}" />
                        </Track.Thumb>
                    </Track>
                </Grid>
            </Border>
            <ControlTemplate.Triggers>
                <Trigger Property="IsSelectionRangeEnabled"
                         Value="true">
                    <Setter TargetName="PART_SelectionRange"
                            Property="Visibility"
                            Value="Visible" />
                </Trigger>
                <Trigger Property="IsKeyboardFocused"
                         Value="true">
                    <Setter TargetName="Thumb"
                            Property="Foreground"
                            Value="Blue" />
                </Trigger>
            </ControlTemplate.Triggers>
        </ControlTemplate>
        <Style TargetType="{x:Type Slider}">
            <Setter Property="Stylus.IsPressAndHoldEnabled"
                    Value="false" />
            <Setter Property="Background"
                    Value="Transparent" />
            <Setter Property="BorderBrush"
                    Value="Transparent" />
            <Setter Property="Foreground"
                    Value="{StaticResource SliderThumb.Static.Foreground}" />
            <Setter Property="Template"
                    Value="{StaticResource SliderHorizontal}" />
        </Style>
    </UserControl.Resources>
    <Slider Height="14"
            Margin="0"
            VerticalContentAlignment="Center"
            Maximum="255"
            Minimum="0"
            Padding="0"
            Value="{Binding RelativeSource={RelativeSource FindAncestor,
                                                           AncestorType={x:Type elements:TinySlider}},
                            Path=Value}" />
</UserControl>
